package br.academic.zumeh.service;

import java.io.Serializable;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;
import javax.transaction.RollbackException;

import org.primefaces.model.UploadedFile;

import br.academic.zumeh.model.User;
import br.academic.zumeh.persistence.UserDAO;
import br.academic.zumeh.util.RequerTransacao;


@Named
public class UserService implements Serializable {
	
	private static final long serialVersionUID = -3890975641781542593L;
	
	
	
	@Inject
	private UserDAO userDao;
	
	public UserService() {
		//users = userDao.listaObjetos();
		//userDao = new UserDAO();
	}

	
	
	public void login() {} 
	
	@RequerTransacao
	public String verifyUser(String login, String password) {
		if (userDao.usuarioExiste(login, password)) {
			return "teste";
		}
		System.out.println("deu erro");
		return "error";
	}
	
	public String createUser() {
		System.out.println("entrou!!!");
		return "createuser";
	}

	public void setUserDao(UserDAO userDao) {
		this.userDao = userDao;
	}



	public void saveUser(String login, String password, String firstName,
			String lastName, String birthDay, String gender, String email,
			String local, String aboutMe) throws RollbackException {

		userDao.createUser(login, password, firstName, lastName, birthDay,
				gender, email, local, aboutMe);

	}


	@RequerTransacao
	public boolean isLoginAvailable(String login) {
		return userDao.getUserByLogin(login) == null;
	}



	public boolean isEmailInUse(String email) {
		return userDao.getUserByEmail(email) != null;
	}



	public List<User> updateUsers() {
		return userDao.listaObjetos();
	}
	
}
